package com.ad.pet.app.mall;

import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ad.pet.Logger;
import com.ad.pet.MainActivity;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.app.collect.CollecContract;
import com.ad.pet.app.collect.CollectPresenter;
import com.ad.pet.app.main.adapter.HomeIndexMallAdapter;
import com.ad.pet.app.main.desniger.DesnigerContract;
import com.ad.pet.app.main.desniger.DesnigerPresenter;
import com.ad.pet.app.mall.adapter.DescribeGoodAdapter;
import com.ad.pet.app.mall.adapter.GoodPhotoAdapter;
import com.ad.pet.app.mall.adapter.GoodRatingAdapter;
import com.ad.pet.app.mall.adapter.GoodRecordAdapter;
import com.ad.pet.app.mall.adapter.ShipAdater;
import com.ad.pet.app.mall.adapter.SkuAdapter;
import com.ad.pet.app.mall.adapter.StroeGoodAdapter;
import com.ad.pet.app.shopcar.ShopingCarPresenter;
import com.ad.pet.app.shopcar.ShoppingCarContract;
import com.ad.pet.common.data.utils.glide.GlideUtil;
import com.ad.pet.common.data.utils.ui.ToastUtil;
import com.ad.pet.common.structure.events.Events;
import com.ad.pet.common.structure.events.RxBus;
import com.ad.pet.common.structure.mvp.BasePresenter;
import com.ad.pet.common.structure.ui.activity.LoadingActivity;
import com.ad.pet.constant.Constant;
import com.ad.pet.models.remote.CommList;
import com.ad.pet.models.remote.User;
import com.ad.pet.models.remote.account.order.OrderType;
import com.ad.pet.models.remote.cart.EditNum;
import com.ad.pet.models.remote.cart.Good;
import com.ad.pet.models.remote.cart.NewProduct;
import com.ad.pet.models.remote.main.DesingerMain;
import com.ad.pet.models.remote.main.DesingerType;
import com.ad.pet.models.remote.mall.ProductDetail;
import com.ad.pet.models.remote.mall.Rating;
import com.ad.pet.models.remote.mall.Record;
import com.ad.pet.models.remote.mall.SkuProps;
import com.ad.pet.models.remote.mall.Skumap;
import com.ad.pet.models.remote.mall.Specification;
import com.ad.pet.ui.ActivityAddChoseDialog;
import com.ad.pet.ui.ShopFirstToCartAgainDialog;
import com.ad.pet.ui.ShopFirstToCartDialog;
import com.ad.pet.ui.ShopOrBuyDialog;
import com.ad.pet.ui.SkuDialog;
import com.ad.pet.ui.TimeLabelZTextview;
import com.ad.pet.ui.loopview.LoopView;
import com.ad.pet.ui.loopview.entity.LoopViewEntity;
import com.ad.pet.utils.LyxUtils;
import com.ad.pet.utils.StatusBarUtil;
import com.ad.pet.utils.UMEventUtil;
import com.ad.pet.utils.UMShareLinstener;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.ShareBoardConfig;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by SEELE on 2018/3/27.商城
 */

public class GoodDetailActivity extends LoadingActivity implements MallContracts.View, CollecContract.View, DesnigerContract.View,ShoppingCarContract.View {

    @BindView(R.id.recycler_shop)
    RecyclerView mRecyclerShop;

    @Inject
    ShopingCarPresenter mShopingCarPresenter;

    @BindView(R.id.tv_follow_shop)
    TextView mTvFollowShop;

    @Inject
    DesnigerPresenter mDesnigerPresenter;

    private StroeGoodAdapter mStoreGoodAdapter;

    @BindView(R.id.tv_dikou)
    TextView mTvDikou;
    @BindView(R.id.loopView)
    LoopView mLoopView;
    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_flash_buy)
    TextView mTvFlashBuy;
    @BindView(R.id.tv_hour)
    TextView mTvHour;
    @BindView(R.id.tv_min)
    TextView mTvMin;
    @BindView(R.id.tv_second)
    TextView mTvSecond;
    @BindView(R.id.tv_price)
    TextView mTvPrice;
    @BindView(R.id.tv_old_price)
    TextView mTvOldPrice;
    @BindView(R.id.tv_off)
    TextView mTvOff;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.tv_sales_number)
    TextView mTvSalesNumber;
    @BindView(R.id.tv_youcan)
    TextView mTvYoucan;
    @BindView(R.id.tv_earn_price)
    TextView mTvEarnPrice;
    @BindView(R.id.tv_flash_sale_info)
    TextView mTvFlashSaleInfo;
    @BindView(R.id.iv_green_gou)
    ImageView mIvGreenGou;
    @BindView(R.id.relate_attr)
    RelativeLayout mRelateAttr;
    @BindView(R.id.rb_normal)
    RatingBar mRbNormal;
    @BindView(R.id.recycler_desc)
    RecyclerView mRecyclerDesc;
    @BindView(R.id.tv_add_cart)
    TextView mTvAddCart;
    @BindView(R.id.tv_buy_now)
    TextView mTvBuyNow;
    @BindView(R.id.recycler_rating)
    RecyclerView mRecyclerRating;
    @BindView(R.id.tv_record)
    TextView mTvRecord;
    @BindView(R.id.relativeLayout_record)
    RelativeLayout mRelativeLayoutRecord;
    @BindView(R.id.recycler_recoard)
    RecyclerView mRecyclerRecoard;

    @BindView(R.id.tv_enter_cart)
    TextView mTvEnterCart;

    @BindView(R.id.tv_store_enter)
    TextView mTvEnterStore;
    @BindView(R.id.tv_collect_good)
    TextView mTvCollectGood;

    //    private BottomSheetDialog mSkuDialog;
    private View mDialogView;

//    @BindView(R.id.iv_share)
//    ImageView mIvShare;

    @BindView(R.id.relate_points)
    RelativeLayout mRelativePoints;

    @BindView(R.id.tv_attr_name)
    TextView mTvAttrName;

    private String productId;

    @Inject
    MallPresenter mMallPresenter;

    @Inject
    CollectPresenter mCollectPresenter;

    @BindView(R.id.linear_canback)
    LinearLayout mLinearCanBack;
    @BindView(R.id.tv_canback)
    TextView mTvCanBack;

    @BindView(R.id.iv_colletion)
    ImageView mIvCollection;

    @BindView(R.id.tv_cart_number)
    TextView mTvCartNumber;
    @BindView(R.id.tv_dikou_title)
            TextView tvDikouTile;

    ProductDetail mProductDetail;


    @BindView(R.id.tv_30Day)
    TextView mTv30dAY;

    @BindView(R.id.tv_rating_show)
    TextView mTextViewRatingShow;

    @BindView(R.id.tv_rating_i)
    TextView mTvRatI;
//    @BindView(R.id.tv_camget)
//    TextView mTvCamget;

    @BindView(R.id.recycler_ship)
    RecyclerView mRecyclerShip;

    private DescribeGoodAdapter mDescribeGoodAdapter;
    private GoodRecordAdapter mGoodRecordAdapter;
    private GoodRatingAdapter mGoodRatingAdapter;
    private RecyclerView mRecyclerSku;
    private ImageView mIvDialogClose;
    private ImageView mIvDialogHead;
    private TextView mTvDialogTitle;
    private TextView mTvDialogPrice;
    private TextView mIvAddNumber;
    private TextView mIvRemove;
    private TextView mTvBuyNumber;
    private SkuAdapter mSkuAdapter;
    private SkuDialog mSkuDialog;
    private TextView mTvDialogChose;
    private TreeMap<Integer, String> mSkuMap;

    private Skumap hasChoseSkumap;
    int mChoseNumber = 1;
    private View mShopBuyDialog;
    private ShopOrBuyDialog mShopOrBuyDialog;
    private ImageView mIvShopDialogClose;
    private TextView mTvDialogTitle1;
    private Button mBtnViewCart;
    private Button mBtnShopContinue;
    @BindView(R.id.iv_refunds)
    ImageView mIvRefunds;
    private ShareBoardConfig mBoardConfig;
    private UMImage mUmImage;
    private UMWeb mUMWeb;

    @BindView(R.id.recycler_photo)
    RecyclerView mRecyclerPhoto;
    private GoodPhotoAdapter mGoodPhotoAdapter;


    @BindView(R.id.recycler_want)
    RecyclerView mRecycelrWant;

    @BindView(R.id.tv_you_want)
    TextView mTvWant;
    private HomeIndexMallAdapter mHomeIndexMallAdapter;

    TextView mTvChiMa;

    @BindView(R.id.tv_share_earn_money)
    TextView mIvShare;

    @BindView(R.id.tv_store)
    TextView mTvStore;
    private ShipAdater mShipAdater;
    private ActivityAddChoseDialog mActivityAddChoseDialog;
    private TimeLabelZTextview mTimeLabelZTextview;
    private TextView mTvCouDan;
    private RelativeLayout mBtnJieSuanActivity;
    private TextView mTv_reduce_price;
    private ShopFirstToCartAgainDialog mShopFirstToCartAgainDialog;
    private ShopFirstToCartDialog mShopFirstToCartDialog;
    private TextView mTvAgainBackPrice;
    private Button mBtnAgainCart;
    private Button mBtnAgainContinue;
    private TextView mTvFirstYue;
    private TextView mTvFirstCanBack;
    private Button mBtnFirstCart;
    private LinearLayout mBtnFirstContinue;
    Drawable drawableTopCHose;
    Drawable drawableTopUnchose;

    @Override
    protected void initViews() {

        drawableTopCHose = getResources().getDrawable(
                R.drawable.ic_detail_chose);
        drawableTopUnchose = getResources().getDrawable(R.drawable.ic_detail_unchose);

        productId = getIntent().getStringExtra(Constant.PRODUCT_ID);
        mMallPresenter.onCreate(this);
        mCollectPresenter.onCreate(this);
        mShopingCarPresenter.onCreate(this);
        mMallPresenter.getGoodDetail(productId);

        if (hasLogin()) {
            mShopingCarPresenter.showCartNumber();
        }
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mActivity);
        mRecyclerDesc.setLayoutManager(linearLayoutManager);
        mDescribeGoodAdapter = new DescribeGoodAdapter(null);
        mRecyclerDesc.setAdapter(mDescribeGoodAdapter);

        LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(mActivity);
        mRecyclerRating.setLayoutManager(linearLayoutManager1);
        mGoodRatingAdapter = new GoodRatingAdapter(null);
        mRecyclerRating.setAdapter(mGoodRatingAdapter);

        LinearLayoutManager linearLayoutManager11 = new LinearLayoutManager(mActivity);
        mRecyclerRecoard.setLayoutManager(linearLayoutManager11);
        mGoodRecordAdapter = new GoodRecordAdapter(null);
        mRecyclerRecoard.setAdapter(mGoodRecordAdapter);

        LinearLayoutManager linearLayout3 = new LinearLayoutManager(mActivity);
        mRecyclerPhoto.setLayoutManager(linearLayout3);
        mGoodPhotoAdapter = new GoodPhotoAdapter(null);
        mRecyclerPhoto.setAdapter(mGoodPhotoAdapter);

        GridLayoutManager linearLayoutManager4 = new GridLayoutManager(mActivity, 2);
        mRecycelrWant.setLayoutManager(linearLayoutManager4);
        mHomeIndexMallAdapter = new HomeIndexMallAdapter(null);
        mRecycelrWant.setAdapter(mHomeIndexMallAdapter);

        LinearLayoutManager linearLayoutManager8 = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        mStoreGoodAdapter = new StroeGoodAdapter(null);
        mRecyclerShop.setLayoutManager(linearLayoutManager8);
        mRecyclerShop.setAdapter(mStoreGoodAdapter);

        mRecyclerShip.setLayoutManager(new LinearLayoutManager(this));
        mShipAdater = new ShipAdater(null);
        mRecyclerShip.setAdapter(mShipAdater);


        mDialogView = LayoutInflater.from(this).inflate(R.layout.layout_sku_chose_dialog, null);
        mRecyclerSku = mDialogView.findViewById(R.id.recycler_sku);
        mIvDialogClose = mDialogView.findViewById(R.id.iv_close_dialog);
        mIvDialogHead = mDialogView.findViewById(R.id.iv_head);
        mTvDialogTitle = mDialogView.findViewById(R.id.tv_title_dialog);
        mTvDialogPrice = mDialogView.findViewById(R.id.tv_dialog_price);
        mIvAddNumber = mDialogView.findViewById(R.id.tv_add);
        mIvRemove = mDialogView.findViewById(R.id.tv_remove);
        mTvBuyNumber = mDialogView.findViewById(R.id.tv_number);
        mTvDialogChose = mDialogView.findViewById(R.id.tv_confir_chose);
        mTvChiMa = mDialogView.findViewById(R.id.tv_chima);
        mIvRemove.setTextColor(getResources().getColor(R.color.graycf));
//02159511369
        LinearLayoutManager linearLayoutManager112 = new LinearLayoutManager(mActivity);
        mRecyclerSku.setLayoutManager(linearLayoutManager112);
        mSkuAdapter = new SkuAdapter(null);
        mRecyclerSku.setAdapter(mSkuAdapter);

        mSkuDialog = new SkuDialog(mActivity, R.style.custom_dialog_style);
        mSkuDialog.setContentView(mDialogView);

        mShopOrBuyDialog = new ShopOrBuyDialog(mActivity, R.style.custom_dialog_style);
        mShopBuyDialog = LayoutInflater.from(this).inflate(R.layout.layout_chose_pay_or_shoping_dialog, null);
        mIvShopDialogClose = mShopBuyDialog.findViewById(R.id.iv_close_paydialog);
        mTvDialogTitle1 = mShopBuyDialog.findViewById(R.id.tv_title_top);
        mBtnViewCart = mShopBuyDialog.findViewById(R.id.btn_view_cart);
        mBtnShopContinue = mShopBuyDialog.findViewById(R.id.btn_continue_shoping);


        mShopOrBuyDialog.setContentView(mShopBuyDialog);


        mActivityAddChoseDialog = new ActivityAddChoseDialog(mActivity, R.style.custom_dialog_style);
        mTimeLabelZTextview = mActivityAddChoseDialog.findViewById(R.id.tv_time_label);
        mTvCouDan = mActivityAddChoseDialog.findViewById(R.id.tv_coudan);
        mBtnJieSuanActivity = mActivityAddChoseDialog.findViewById(R.id.btn_jiesuan_ac);
        mTv_reduce_price = mActivityAddChoseDialog.findViewById(R.id.tv_reduce_price);

        mShopFirstToCartAgainDialog = new ShopFirstToCartAgainDialog(mActivity, R.style.custom_dialog_style);
        mTvAgainBackPrice = mShopFirstToCartAgainDialog.findViewById(R.id.tv_shop_dialog_canback);
        mBtnAgainCart = mShopFirstToCartAgainDialog.findViewById(R.id.btn_view_cart);
        mBtnAgainContinue = mShopFirstToCartAgainDialog.findViewById(R.id.btn_continue_shoping);


        mShopFirstToCartDialog = new ShopFirstToCartDialog(mActivity, R.style.custom_dialog_style);
        mTvFirstYue = mShopFirstToCartDialog.findViewById(R.id.tv_shop_dialog_yue);
        mTvFirstCanBack = mShopFirstToCartDialog.findViewById(R.id.tv_shop_dialog_canback);
        mBtnFirstCart = mShopFirstToCartDialog.findViewById(R.id.btn_view_cart);
        mBtnFirstContinue = mShopFirstToCartDialog.findViewById(R.id.btn_continue_shoping);


//        mActivityAddChoseDialog.show();


        mBoardConfig = new ShareBoardConfig();
        mBoardConfig.setIndicatorVisibility(false);
        mBoardConfig.setTitleText(getString(R.string.share));
        mBoardConfig.setCancelButtonText(getString(R.string.cancel));


//        mSkuDialog = new SkuDialog(this,R.style.custom_dialog_style);
//        mSkuDialog.setContentView(mDialogView);
//        mSkuDialog.getWindow().findViewById(R.id.design_bottom_sheet)
//                .setBackgroundResource(android.R.color.transparent);
//        BottomSheetUtil.statusBarTranslucent(mSkuDialog);


    }

    @Override
    protected void initData() {

        mMallPresenter.getRateList(productId, "1", "5");
        mMallPresenter.getSaleRecord(productId, "1", "5");
        mSkuMap = new TreeMap<>();

        mDesnigerPresenter.onCreate(this);

    }

    @Override
    protected void initEvents() {


        mTvEnterStore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Navigation.goDesignerStoreList(mActivity, mProductDetail.getStore_id(), mProductDetail.getStore_name(), MainActivity.REQUEST_GO_MALL);
            }
        });
        mTvEnterCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("goHome", 2);
                setResult(RESULT_OK, intent);
                finish();
            }
        });

        mTvCollectGood.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mProductDetail == null) {
                    return;
                }
                if (!hasLogin()) {
                    Navigation.goLogin(mActivity, 23, 0);
                    return;
                }

                if (0 == mProductDetail.getIs_in_wishlist()) {
                    Map mCollectMap = new HashMap();
                    mCollectMap.put("item", mProductDetail.getName());
                    MobclickAgent.onEvent(mActivity, "__collect", mCollectMap);
                } else {
                }
                RxBus.getDefault().post(new Events.Collection());
            }
        });
        mStoreGoodAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (mStoreGoodAdapter.getData().get(position).isEnd()) {
//                    Navigation.goDesignerStoreList(mActivity, mProductDetail.getStore_id(), mProductDetail.getStore_name(), MainActivity.REQUEST_GO_MALL);
                } else {
                    Navigation.goGoodDetail(mActivity, MainActivity.REQUEST_GO_MALL, mStoreGoodAdapter.getData().get(position).getProduct_id());
                }
            }
        });
        mRelateAttr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                BottomSheetUtil.collapsedDialog(mDialogView);
//                mSkuDialog.show();
                mSkuDialog.show();

            }
        });
        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mRelativePoints.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Navigation.goGoodRateList(mActivity, productId);
            }
        });
        mIvCollection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("goHome", 1);
                setResult(RESULT_OK, intent);
                finish();
//                if (mProductDetail == null) {
//                    return;
//                }
//                if (!hasLogin()) {
//                    Navigation.goLogin(mActivity, 23, 0);
//                    return;
//                }
//
//                if (0 == mProductDetail.getIs_in_wishlist()) {
//                    mCollectPresenter.addCollectTag(productId, "0");
//                    Map mCollectMap = new HashMap();
//                    mCollectMap.put("item", mProductDetail.getName());
//                    MobclickAgent.onEvent(mActivity, "__collect", mCollectMap);
//                } else {
//                    mCollectPresenter.delCollectGoods("0", productId);
//                }
//                RxBus.getDefault().post(new Events.Collection());
            }
        });
        mRelativeLayoutRecord.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Navigation.goRecordList(mActivity, productId);
            }
        });

        mIvDialogClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSkuDialog.dismiss();
            }
        });

        mSkuAdapter.setOnSkuItemClickLinstenr(new SkuAdapter.OnSkuItemClickLinstenr() {
            @Override
            public void onSkuItemClick(int positon, int itemPosition) {

                List<SkuProps> skuProps = mSkuAdapter.getData();
                mSkuMap.put(positon, skuProps.get(positon).getValue().get(itemPosition).getName());


                StringBuffer selectSku = new StringBuffer();
                Set set = mSkuMap.keySet();//用接口实例接口
                Iterator iter = set.iterator();
                while (iter.hasNext()) {//遍历二次,速度慢
//                    selectSku = selectSku + "&gt;" + selectSku;
                    selectSku.append(mSkuMap.get(((Integer) iter.next())));
                    selectSku.append("&gt;");
                }
                if (selectSku.length() != 0) {
                    selectSku.delete(selectSku.length() - 4, selectSku.length());
                }
                for (Skumap skuMap : mProductDetail.getSkuMap()) {
                    if (TextUtils.equals(skuMap.getSku_option(), selectSku.toString())) {
                        hasChoseSkumap = skuMap;
                        break;
                    }
                }
                if (hasChoseSkumap != null) {
                    mTvDialogPrice.setText(mProductDetail.getCurrency_symbol() + ((TextUtils.isEmpty(hasChoseSkumap.getPrice()) || TextUtils.equals("0", hasChoseSkumap.getPrice())) ? mProductDetail.getPrice() : hasChoseSkumap.getPrice()));
                    mTvDialogTitle.setText(selectSku.toString().replaceAll("&gt;", ","));
                }
//                Logger.e("select_sku-->" + selectSku.toString());
            }
        });
        mTvDialogChose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSkuAdapter.getUnselectPosition() != -1) {
                    ToastUtil.getToastUtil().showShort(mSkuAdapter.getData().get(mSkuAdapter.getUnselectPosition()).getProp());
                    return;
                }
                if (mSkuAdapter.getData().size() > 0 && hasChoseSkumap == null) {
                    ToastUtil.getToastUtil().showShort(getString(R.string.this_sku_no_good));
                    return;
                }

                if (!hasLogin()) {
                    Navigation.goLogin(mActivity, 23, 0);
                    return;
                }
                mMallPresenter.addToCart(productId, mTvBuyNumber.getText().toString(), hasChoseSkumap == null ? "" : hasChoseSkumap.getSkuId(), TextUtils.isEmpty(mProductDetail.getStore_id()) ? "" : mProductDetail.getStore_id());
//                mSkuDialog.hide();


            }
        });
        mIvAddNumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSkuAdapter.getUnselectPosition() != -1) {
                    ToastUtil.getToastUtil().showShort(mSkuAdapter.getData().get(mSkuAdapter.getUnselectPosition()).getProp());
                    return;
                }
                int maxNumber = (hasChoseSkumap != null ? hasChoseSkumap.getCanBookCount() : mProductDetail.getStock());
                if (mChoseNumber < maxNumber) {
                    mChoseNumber++;
                } else {
                    mChoseNumber = maxNumber;
                    ToastUtil.getToastUtil().showShort(getString(R.string.edit_cart_number_failed_max_tips));
                }

                mTvBuyNumber.setText(String.valueOf(mChoseNumber));
                if (mChoseNumber <= 1) {
                    mIvRemove.setTextColor(getResources().getColor(R.color.graycf));
                } else {
                    mIvRemove.setTextColor(getResources().getColor(R.color.gray34));
                }

            }
        });
        mIvRemove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mSkuAdapter.getUnselectPosition() != -1) {
                    ToastUtil.getToastUtil().showShort(mSkuAdapter.getData().get(mSkuAdapter.getUnselectPosition()).getProp());
                    return;
                }

                if (mChoseNumber > 1) {
                    mChoseNumber--;
                } else {
                    mChoseNumber = 1;

                }

                mTvBuyNumber.setText(String.valueOf(mChoseNumber));

                if (mChoseNumber <= 1) {
                    mIvRemove.setTextColor(getResources().getColor(R.color.graycf));
                } else {
                    mIvRemove.setTextColor(getResources().getColor(R.color.gray34));
                }
            }
        });

        mTvAddCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!hasLogin()) {
                    Navigation.goLogin(mActivity, 78, 0);
                    return;
                }

                mSkuDialog.show();
            }
        });

        mBtnViewCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("goHome", 2);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        mBtnShopContinue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mShopOrBuyDialog.dismiss();
            }
        });

        mBtnAgainCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("goHome", 2);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        mBtnAgainContinue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mShopFirstToCartAgainDialog.dismiss();
            }
        });

        mBtnFirstCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("goHome", 2);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        mBtnFirstContinue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mShopFirstToCartDialog.dismiss();
            }
        });

        mIvShopDialogClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mShopOrBuyDialog.dismiss();
            }
        });
        mIvRefunds.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Navigation.goCommonWebView(mActivity, getString(R.string.returns_and_refunds_policy), LyxUtils.muchLuanguageUrl("/about/refundspolicy.html"));
            }
        });

        mIvShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UMEventUtil.onEvent(mActivity, "share_good_detail_event");
                if (mProductDetail == null) {
                    return;
                }
                mUmImage = new UMImage(mActivity, mProductDetail.getImage().get(0));
                mUMWeb = new UMWeb(mProductDetail.getShare_product_url());
                mUMWeb.setThumb(mUmImage);
                mUMWeb.setTitle("这个东东不错还包邮，我已经拍了，你帮我看看怎么样？");
                mUMWeb.setDescription(mProductDetail.getName());
                new ShareAction(mActivity)
                        .withMedia(mUMWeb)
                        .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ, SHARE_MEDIA.FACEBOOK)
                        .setCallback(new UMShareLinstener()).open(mBoardConfig);


            }
        });
        mTvChiMa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Navigation.goCommonWebView(mActivity, mTvChiMa.getText().toString(), LyxUtils.muchLuanguageUrl("/sizechart"));
            }
        });

        mTvStore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Navigation.goDesignerStoreList(mActivity, mProductDetail.getStore_id(), mProductDetail.getStore_name(), MainActivity.REQUEST_GO_MALL);
            }
        });

        mBtnJieSuanActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("goHome", 2);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
        mTvCouDan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mActivityAddChoseDialog.dismiss();
            }
        });


    }

    @Override
    public void initInject() {
        DaggerMallCompent.builder().applicationComponent(getApplicationComponent()).activityModule(getActivityModule()).build().inject(this);
    }

    @Override
    protected BasePresenter getPresenter() {
        return mMallPresenter;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void error(String msg) {
        ToastUtil.getToastUtil().showShort(msg);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null)
            return;
        switch (requestCode) {

            case MainActivity.REQUEST_GO_MALL:
                setResult(RESULT_OK, new Intent());
                finish();

                break;
        }
    }


    @Override
    public void error(int code, String msg) {
        ToastUtil.getToastUtil().showShort(msg);
        if (code == 402)
            mStatusLayoutManager.showNetWorkError();
    }

    @Override
    protected int contentLayout() {
        return R.layout.activity_mall;
    }

    @Override
    protected void clickRetry(View v) {

    }

    @Override
    protected void setContentViewBefore() {
        super.setContentViewBefore();
        StatusBarUtil.setTranslucentStatus(this);
    }

    @Override
    public void getGoodDetailSuceess(ProductDetail productDetail) {
        this.mProductDetail = productDetail;
//        mIvCollection.setImageResource(0 == mProductDetail.getIs_in_wishlist() ? R.drawable.ic_detail_uncollect : R.drawable.ic_detail_collect);
        mTvCollectGood.setCompoundDrawablesWithIntrinsicBounds(null, 0 == mProductDetail.getIs_in_wishlist() ? drawableTopUnchose : drawableTopCHose, null, null);



        List<LoopViewEntity> loopViewEntities = new ArrayList<>();
        for (int i = 0; i < mProductDetail.getImage().size(); i++) {
            loopViewEntities.add(new LoopViewEntity(productDetail.getImage().get(i)));
        }
        mLoopView.setLoopData(loopViewEntities);

        mGoodPhotoAdapter.setNewData(productDetail.getImage());

        if (!TextUtils.isEmpty(productDetail.getFloat_click_text())) {
            mLinearCanBack.setVisibility(View.VISIBLE);
        } else {
            mLinearCanBack.setVisibility(View.GONE);
        }

        mTvPrice.setText(productDetail.getCurrency_symbol() + productDetail.getPrice());
        mTvCanBack.setText(productDetail.getCurrency_symbol() + productDetail.getFloat_click_text());
        mTvOldPrice.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        mTvOldPrice.setText(productDetail.getCurrency_symbol() + productDetail.getOrig_price());
        mTvOff.setText(productDetail.getDiscount() + "%off");
        mTvTitle.setText(productDetail.getName());
        mTvEarnPrice.setText(productDetail.getCurrency_symbol() + LyxUtils.formatSubtract(Double.valueOf(productDetail.getOrig_price()), Double.valueOf(productDetail.getPrice())));
        mTvFlashSaleInfo.setVisibility(View.GONE);
//        mTv30dAY.setText(productDetail.getPage_product_return_refund());
        mTextViewRatingShow.setText(productDetail.getAverage_rating() + "/5");
        mTvRatI.setText(productDetail.getTotal_reviews() + " " + productDetail.getPage_product_rate());
        mRbNormal.setRating(Float.parseFloat(productDetail.getAverage_rating()));
        mTvSalesNumber.setText(productDetail.getSales() + " " + getString(R.string.has_buy));
        mShipAdater.setNewData(productDetail.getTransport());
        mTvDikou.setText(productDetail.getAfter_discount_price_text());
        if (TextUtils.isEmpty(productDetail.getAfter_discount_price_text())) {
            mTvDikou.setVisibility(View.INVISIBLE);
            tvDikouTile.setVisibility(View.INVISIBLE);
        }

        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < productDetail.getSkuProps().size(); i++) {
            stringBuffer.append(productDetail.getSkuProps().get(i).getProp());
            if (i != productDetail.getSkuProps().size() - 1) {
                stringBuffer.append(",");
            }
        }
        if (stringBuffer.length() == 0) {
            stringBuffer.append(getString(R.string.number));
        }
        mTvAttrName.setText(stringBuffer.toString());


        List<Specification> specifications = productDetail.getSpecification();
        if (!TextUtils.isEmpty(productDetail.getWish_specification())) {
            specifications = new ArrayList<>();
            String[] wss = productDetail.getWish_specification().split("\n");
            for (int i = 0; i < wss.length; i++) {
                if (!TextUtils.isEmpty(wss[i]))
                    specifications.add(new Specification(wss[i]));
            }
        }
        mDescribeGoodAdapter.setNewData(specifications);
        mTvRecord.setText(productDetail.getPage_product_transaction_recode());

        if (productDetail.getImage() != null && productDetail.getImage().size() >= 1) {
            GlideUtil.load(mActivity, productDetail.getImage().get(0), mIvDialogHead);
        }
        mTvDialogTitle.setText(productDetail.getName());
        mSkuAdapter.setNewData(mProductDetail.getSkuProps());
        mTvDialogPrice.setText(mProductDetail.getCurrency_symbol() + productDetail.getPrice());

        mTvStore.setText(productDetail.getStore_name());
//        mTvWant.setText(productDetail.getPage_product_also_like());
        mHomeIndexMallAdapter.setNewData(mProductDetail.getCategory_product_list());
        mStatusLayoutManager.showContent();


    }

    @Override
    public void getRateListSuccess(List<Rating> ratings) {
        mGoodRatingAdapter.setNewData(ratings);
    }

    @Override
    public void getSaleRecordSuccess(List<Record> records) {
        mGoodRecordAdapter.setNewData(records);
    }

    @Override
    public void addToCartSuccess(User cartSuccessBean) {

        if (cartSuccessBean.getIs_new_user_pop_type() == 1) {
//            mActivityAddChoseDialog.show();

//            mTimeLabelZTextview.setDownTimeStart((int) cartSuccessBean.getTime_left(), new TimeLabelZTextview.onDownTimeLinstener() {
//                @Override
//                public void onTimeEnd() {
//                    mActivityAddChoseDialog.dismiss();
//                }
//            });
//
//            mTv_reduce_price.setText(getString(R.string.can_jieyue) + mProductDetail.getCurrency_symbol() + cartSuccessBean.getMoney_saved());
            mTvFirstYue.setText(cartSuccessBean.getPrice_head());
            mTvFirstCanBack.setText(cartSuccessBean.getPrice_foot());
            mShopFirstToCartDialog.show();
        } else if (cartSuccessBean.getIs_new_user_pop_type() == 2) {
            mTvAgainBackPrice.setText(cartSuccessBean.getPrice_head());
            mShopFirstToCartAgainDialog.show();


        } else {
//            mShopOrBuyDialog.show();
            ToastUtil.getToastUtil().showShort("添加购物车成功");
        }

        mSkuDialog.dismiss();



        try {
            RxBus.getDefault().post(new Events.AddCarts());
        } catch (Exception e) {
            Logger.e(e.getMessage());
        }
        mShopingCarPresenter.showCartNumber();

    }

    @Override
    public void getFlashListSuccess(CommList<List<Good>> commList) {

    }


    @Override
    protected void onPause() {
        Glide.get(mActivity).clearMemory();
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        Glide.get(mActivity).clearMemory();
        super.onDestroy();
    }




    @Override
    public void getDesginerShopSuccess(List<DesingerMain> store) {

    }

    @Override
    public void getShopServiceSuccess(List<DesingerType> shopServices) {

    }

    @Override
    public void getStoreDetailSuccess(DesingerMain desingerMain) {

    }


    @Override
    public void getCartListSuccess(CommList<List<Good>> good) {

    }

    @Override
    public void editCartSuccess(EditNum editNum) {

    }

    @Override
    public void delCartSuccess() {

    }

    @Override
    public void getCartPriceSuccess(EditNum editNum) {

    }

    @Override
    public void showCartNumberSuccess(User user) {
            if (user.getCart_num()==0){
                mTvCartNumber.setVisibility(View.GONE);
            }else {
                mTvCartNumber.setVisibility(View.VISIBLE);
            }

            mTvCartNumber.setText((user.getCart_num()<=99?user.getCart_num():99)+"");
    }

    @Override
    public void changeChoseStudentsSuccess() {

    }

    @Override
    public void newGetCartProductSuccess(NewProduct newProduct) {

    }

    @Override
    public void getCollectGoodsSuccess(List<OrderType> allGood) {

    }
}
